|
|
// POV-Ray 3.7 Scene File "softshape.inc"
// author: Ingo Janssen
// date: 2023-07-17
// version: 0.5 beta
//
// SoftShape is inspired by Remco de Korte's SoftText, it does not use the same
// layout of arrays as SoftText. SoftShape traces an object in a predifined
// area in steps op 1 pov-unit. The area is in the xy-plane and starts at
// <0,0,0>.
//
// For each point where the trace is successfull the found coordinate is
// written to an include file, as is the normal at that point. In the demo
// scene at the end of the generated include file the points are used for the
// sphere of a blob object.
//
// At the end of this include file is a demo scene to illustrate its use. Just
// run this include file and a new include file 'test_soft.inc' or 'test_colour'
// is generated. Select one of them at the end of this file.
//
// Run this new include file to see the result of the tracing as a blob object.
//
//--------------------------------------------------------------------------
#version 3.7;
#include "functions.inc"
//-- Local macros
// local macro to write (vector) arrays to file
#macro _WriteArray(ObjName, ArrayName, Array, PCount, NCount)
#write(SoftInc, "#declare ",ObjName, ArrayName," =
array[",str(PCount,0,0),"]{\n\t")
#local LineEnd = 1;
#for (I,0, NCount-1)
#ifdef(Array[I])
#write (SoftInc, Array[I],", ")
#if (LineEnd = 30)
#write(SoftInc, "\n\t")
#local LineEnd = 0;
#end
#local LineEnd = LineEnd + 1;
#end
#end
#write(SoftInc,"\n}\n\n")
#end
// local macro to write the include file header to file
#macro _WriteHeader(ObjName)
#write(SoftInc, "#version 3.7;\n\n#ifndef(",ObjName,"_INC_TEMP)
#declare ",ObjName,"_INC_TEMP = version;
#ifdef(View_POV_Include_Stack)
#debug \"including ",ObjName,".inc\"
#end\n\n" )
#end
// local macro to write the include file footer to file
#macro _WriteFooter(ObjName)
#write(SoftInc,"\n\n#version ",ObjName,"_INC_TEMP;
#end //#ifndef(",ObjName,"_INC_TEMP)\n")
#end
// local macro to write a simple demoscene to the inc file.
#macro _WriteDemo(ObjName)
#write(SoftInc,"// test scene
#if(input_file_name=\"",ObjName,".inc\")
global_settings{
assumed_gamma 1.0
}
#default{
finish{
ambient 0.1 diffuse 0.9
}
}
blob{
threshold .7
#declare I = 0;
#for (I,0,",ObjName,"_PCount-1)
sphere{",ObjName,"_Points[I], ",ObjName,"_SS, 1}
#end
pigment{rgb<1,0,1>}
}
light_source{
<",ObjName,"_CentHor, ",ObjName,"_CentVer, -",ObjName,"_SizeHor>
colour rgb 1
shadowless
}
camera{
orthographic
angle 30
location <",ObjName,"_CentHor, ",ObjName,"_CentVer, -",ObjName,"_SizeHor>
look_at <",ObjName,"_CentHor, ",ObjName,"_CentVer, ",ObjName,"_SizeHor>
right x*image_width/image_height
}
#end"
)
#end
//-- Public macros
//==
// The RenderObject macro is a helper macro to visualise the area and object to
// trace. It will render a green area of the dimension that will be traced and
// the object to be traced.
//
// Use:
// Create a POV-Ray scene, include softshape.inc. In the scene only add an
// object{} and this macro. Render the scene. The macro sets the camera and
// lighting.
//
// TIP: set the image size to match the aspect ration of the scan area.
//
// RenderObject(SizeHor, SizeVer, Obj)
//
// Parameters:
// SizeHor (int): horizontal size of the area to be traced
// SizeVer (int): vertical size of the area to be traced
// Obj (object) : object to be traced
//
// Result:
// An image.
//
#macro RenderObject(SizeHor, SizeVer, Obj)
global_settings{
assumed_gamma 1.0
}
#default{
finish{
ambient 0.1 diffuse 0.9
}
}
#local CentHor = SizeHor/2;
#local CentVer = SizeVer/2;
box{
<0,0,-0.001>, <SizeHor, SizeVer, -0.0001>
texture{pigment {rgbt <0,1,0,0.98>}}
}
object{Obj}
light_source{
<SizeHor/2, SizeVer/2, -SizeHor>
colour rgb 1
shadowless
}
camera{
orthographic
angle 30
location <SizeHor/2, SizeVer/2, -SizeHor>
look_at <SizeHor/2, SizeVer/2, SizeHor>
right x*image_width/image_height
}
#end
//==
// The TraceObject macro traces the area <0, 0, 0>, <SizeHor, SizeVer, 0> for
// intersections with the Obj object in one pov-unit steps. It writes the found
// intersection points an normals to the file ObjName".inc".
//
// TraceObject(SizeHor, SizeVer, Obj, ObjName)
// Parameters:
// SizeHor (int): horizontal size of the area to be traced
// SizeVer (int): vertical size of the area to be traced
// Obj (object) : object to be traced
// ObjName (string): the base of the .inc file. The ObjName is also prepend to
// variable names in the include file.
//
// Result:
// An include file containing dimensional data, an array with Points, an array
// with Normals and a demo scene.
//
#macro TraceObject(SizeHor, SizeVer, Obj, ObjName)
#local CentHor = SizeHor/2;
#local CentVer = SizeVer/2;
#local PCount = 0;
#local NCount = SizeHor * SizeVer;
#local Points = array[NCount];
#local Normals = array[NCount];
#local N = 0;
#for(J, SizeVer-1,0,-1)
#for(I, 0, SizeHor-1)
#local Start = <I, J, -SizeHor>;
#local Norm = <0,0,0>;
#local Inter = trace(Obj, Start, <I, J, 0> - Start, Norm);
#if(vlength(Norm)!=0 )
#local Points[N] = <I, J, 0>;
#local Normals[N] = Norm;
#local PCount = PCount + 1;
#end
#local N = N + 1;
#end
#end
#local FileName = concat(ObjName,".inc")
#fopen SoftInc FileName write
_WriteHeader(ObjName)
#write(SoftInc, "#declare ",ObjName,"_SS = 3; //sphere_size\n")
#write(SoftInc, "#declare ",ObjName,"_PCount = ", str(PCount,0,0), ";\n")
#write(SoftInc, "#declare ",ObjName,"_SizeHor = ", str(SizeHor,0,0),";\n")
#write(SoftInc, "#declare ",ObjName,"_SizeVer = ", str(SizeVer,0,0),";\n")
#write(SoftInc, "#declare ",ObjName,"_CentHor = ", str(CentHor,-1,-1),";\n")
#write(SoftInc, "#declare ",ObjName,"_CentVer = ", str(CentVer,-1,-1),";\n\n")
_WriteArray(ObjName, "_Points", Points, PCount, NCount)
_WriteArray(ObjName, "_Normals", Normals, PCount, NCount)
_WriteDemo(ObjName)
_WriteFooter(ObjName)
#fclose SoftInc
#end
#macro RenderPattern(SizeHor, SizeVer, PatFunc)
global_settings{
assumed_gamma 1.0
}
#default{
finish{
ambient 0.1 diffuse 0.9
}
}
#local CentHor = SizeHor/2;
#local CentVer = SizeVer/2;
box{
<0,0,0>, <SizeHor, SizeVer, 0.0001>
pigment{
function{PatFunc(x,y)}
}
}
light_source{
<SizeHor/2, SizeVer/2, -SizeHor>
colour rgb 1
shadowless
}
camera{
orthographic
angle 30
location <SizeHor/2, SizeVer/2, -SizeHor>
look_at <SizeHor/2, SizeVer/2, SizeHor>
right x*image_width/image_height
}
#end
#macro TracePattern(SizeHor, SizeVer, PatFunc, Colour, Distance, ObjName)
#local CentHor = SizeHor/2;
#local CentVer = SizeVer/2;
#local PCount = 0;
#local NCount = SizeHor * SizeVer;
#local Points = array[NCount];
#local Distances = array[NCount];
#local N = 0;
#for(J, SizeVer-1,0,-1)
#for(I, 0, SizeHor-1)
#local Col = PatFunc(I,J);
#if(vlength(Colour - Col) <= Distance )
#local Points[N] = <I, J, 0>;
#local Distances[N] = vlength(Colour - Col);
#local PCount = PCount + 1;
#end
#local N = N + 1;
#end
#end
#local FileName = concat(ObjName,".inc")
#fopen SoftInc FileName write
_WriteHeader(ObjName)
#write(SoftInc, "#declare ",ObjName,"_SS = 3; //sphere_size\n")
#write(SoftInc, "#declare ",ObjName,"_PCount = ", str(PCount,0,0), ";\n")
#write(SoftInc, "#declare ",ObjName,"_SizeHor = ", str(SizeHor,0,0),";\n")
#write(SoftInc, "#declare ",ObjName,"_SizeVer = ", str(SizeVer,0,0),";\n")
#write(SoftInc, "#declare ",ObjName,"_CentHor = ", str(CentHor,-1,-1),";\n")
#write(SoftInc, "#declare ",ObjName,"_CentVer = ", str(CentVer,-1,-1),";\n\n")
_WriteArray(ObjName, "_Points", Points, PCount, NCount)
_WriteArray(ObjName, "_Distances", Distances, PCount, NCount)
_WriteDemo(ObjName)
_WriteFooter(ObjName)
#fclose SoftInc
#end
//===
#if(input_file_name="softshape.inc")
//+w600 +h300 +a0.1
#include "rand.inc"
#declare Stream = seed(7);
//object to be traced
#declare Soft = object{
union{
#for (J,0,1)
#for(I,0,8)
#declare P = Rand_Bernoulli(0.5, Stream);
#if (P)
box{
<10,10,0>,<20,30,1>
translate <I*15,J*35,0>
texture{pigment{rgb 1}}
}
#else
cylinder{
<15,10,0>,<15,30,0>, 5
translate <I*15,J*35,0>
texture{pigment{rgb 1}}
}
#end
#end
#end
sphere{
<0,0,0>,9
texture{pigment{rgb 1}}
}
sphere{
<150,0,0>,9
texture{pigment{rgb 1}}
}
sphere{
<150,75,0>,9
texture{pigment{rgb 1}}
}
sphere{
<0,75,0>,9
texture{pigment{rgb 1}}
}
}
}
//uncomment one of the options below
// option test_soft
//#declare Name = "test_soft"; //will be the name of the include file
//RenderObject(150, 75, Soft)
//TraceObject(150, 75, Soft, Name)
// option test_colour
#declare Name = "test_colour";
#declare FunFunc = function(x,y) {
f_wood(x/20,y/20,z/20)
};
RenderPattern(150, 75, FunFunc)
TracePattern(150, 75, FunFunc, <0.5,0.5,0.5>, 0.2, Name)
#end
Post a reply to this message
|
|